import CryptoJS from 'crypto-js'
// 十六位十六进制数作为密钥偏移量
const iv = CryptoJS.enc.Utf8.parse('c558Gq0YQK2QUlMc')
// 加密
export function aesEncrypt (word, key) {
  key = CryptoJS.enc.Utf8.parse(key)
  let srcs = CryptoJS.enc.Utf8.parse(word)
  let encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 })
  return encrypted.toString()
}
// 解密
export function aesDecrypt (word, key) {
  key = CryptoJS.enc.Utf8.parse(key)
  let value = CryptoJS.AES.decrypt(word, key, { iv: iv, mode: CryptoJS.mode.CBC })
  return CryptoJS.enc.Utf8.stringify(value).toString()
}
